#include "xTextureManager.h"
#include "XEngine.h"
#include "xEngineConfig.h"
#include "xTexture.h"

namespace XE	
{

	xTextureManager* Singleton<xTextureManager>::ms_Singleton = NULL;
	xString  xTextureManager::ReourceType = "Texture";

	xTextureManager::xTextureManager()
	{
		const xEngineConfig& config = XEngine::getSingleton().GetConfig();
		const  xStringVector* Pathlist = config.GetResourceList(xTextureManager::ReourceType);
		if(Pathlist!=NULL)
		{
			xStringVector::const_iterator it = Pathlist->begin();
			for(;it!=Pathlist->end();++it)
			{
				AddPath(*it);
			}
		}



	}
	xTextureManager::~xTextureManager()
	{

	}


	const xString& xTextureManager::GetType()
	{
		return ReourceType;
	}



	xResourcePtr xTextureManager::CreateRenderTexture(const xString& name,UINT width,UINT height,xFormat format)
	{
		 xTextureCreateParameter textpar (name,width,height,format,0,D3DPOOL_DEFAULT,0,true);
		 
		 return CreateResource(&textpar);

	}



	xTexturePtr xTextureManager::CreateNormalTexture(const xString& name,const xTexturePtr& pTextre)
	{
		if(pTextre.isNull())
			return pTextre;
		if(GetByName(name).isNull())
		{
			xLogMessager::getSingleton().logMessage("Create normal Texture Err,there are same texture:"+name);
			return xTexturePtr();
		}
		if(pTextre->GetTextureType()!=TEXTURE_2D)
		{
			xLogMessager::getSingleton().logMessage("Create NormalTexture err ,the texture is no 2d nameis "+name);
			return xTexturePtr();
		}
	    xTexturePtr	 pNormal = CreateNormalTextureImplement(name,pTextre);
		if(pNormal.isNull()==false)
		{
			m_ResourceList.insert(std::make_pair(name,pNormal));
		}
		return pNormal;

	}



	




}